package com.smu.recognize.Util;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

public class DateCompare {

    public static void main(String[] args){
        boolean flag = isDateBefore("2004-09-09 12:12:12","2004-09-09 12:12:12");
        System.out.println(flag);
        flag = isDateBefore("2006-09-09 01:01:01","2005-09-09 16:00:00");
        System.out.println(flag);
        flag = isDateBefore("2005-09-09 01:01:01");
        System.out.println(flag);
    }

    //判断时间date1是否在时间date2之前
    //时间格式 2005-4-21 16:16:34
    public static boolean isDateBefore(String date1,String date2){
        try{
            DateFormat df = DateFormat.getDateTimeInstance();
            return df.parse(date1).before(df.parse(date2));
        }catch(ParseException e){
            System.out.print("[SYS] " + e.getMessage());
            return false;
        }
    }
    //判断当前时间是否在时间date2之前
    //时间格式 2005-4-21 16:16:34
    public static boolean isDateBefore(String date2){
        try{
            Date date1 = new Date();
            System.out.println(date1);
            DateFormat df = DateFormat.getDateTimeInstance();
            return date1.before(df.parse(date2));
        }catch(ParseException e){
            System.out.print("[SYS] " + e.getMessage());
            return false;
        }
    }
}
